<?php

class Tablet_MediaController extends Zend_Controller_Action
{
    var $MediaIndex;
    public function init()
    { 
        Zend_Session::start();
        $Session = new Zend_Session_Namespace ('Params'); 
        $this->view->Persisted = $Session->Persisted;
        $this->_helper->layout->setLayout('ios');
        $this->MediaIndex = new Default_Model_MediaIndex;  
        $this->view->links = array ( 
                                     array ('text'=>'Home', 'href'=>'/tablet/index/index') , 
                                     array ('text'=>'Bookmarks', 'href'=>'/tablet/favorites/index') 
                              );
        $this->view->anchor_left = array ('text'=>'Back',
                                            'href'=>$this->view->links[0]['href']
                                             );
    }

    public function indexAction()
    {
        
        $this->view->groups  = $this->MediaIndex->Groups;  
        $this->view->title   = sprintf("%s - Media", APP_NAME);
        $this->view->links[] = array ('text'=>'Media',    
                                        'active'=>true
                                      );

    }

    public function listAction()
    {
        $request    = $this->getRequest(); 
        $groupname  = $request->getParam('group'); 
        $pagenumber = $request->getParam('page'); 
        if (!isset($pagenumber)) $pagenumber=1;
        $this->MediaIndex->GetFiles ($groupname, 1); 

        $this->view->title = $groupname;
        $this->view->page  = $pagenumber;
        $this->view->files = $this->MediaIndex->Files;
 
        $startIndex  = ($pagenumber - 1) * 10; 
        $this->view->sets    = array_slice ($this->view->files, $startIndex, 10);


        $this->view->anchor_left = array ('text'=>'Back',
                                            'href'=>$this->view->url ( array('action'=>'index', 'group'=>NULL) )
                                             );
        $this->view->links[] = array ('text'=>'Media',  
                                        'href'=>$this->view->url ( array('action'=>'index', 'group'=>NULL) )
                                      );
        $this->view->links[] = array ('text'=>$groupname,     
                                        'active'=>true
                                      );
    }

    public function viewAction()
    {
        $request = $this->getRequest(); 
        $groupname  = $request->getParam('group'); 
        $id         = $request->getParam('id'); 

        $this->MediaIndex->GetArticle($groupname, $id);

        $this->view->article = $this->MediaIndex->Article;
        $this->view->files   = $this->MediaIndex->Files; 

        $this->view->title   = $this->view->article['subject'];
        $this->view->anchor_left = array ('text'=>'Back',
                                            'href'=>$this->view->url ( array('action'=>'list', 'id'=>NULL) )
                                             );
        $this->view->links[] = array ('text'=>'Media',  
                                        'href'=>$this->view->url ( array('action'=>'index', 'group'=>NULL) )
                                      );
        $this->view->links[] = array ('text'=>$groupname,  
                                        'href'=>$this->view->url ( array('action'=>'list', 'id'=>NULL) )
                                      );
        $this->view->links[] = array ('text'=>$this->view->title,     
                                        'active'=>true
                                      );
    }


}





